<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>供应商穿梭框</title>
    <link rel="stylesheet" type="text/css" href="../../layui-transfer/layui/layui/css/layui.css"/>
</head>
<body>

<div id="root"></div>
<button  class="layui-btn" id="queding">确定</button>

<button  class="layui-btn" id="quxiao">取消</button>
<script src="../../layui-transfer/layui/layui/layui.js"></script>

<script>
    var transfer;
    var $;
    layui.config({
        base: '../../layui-transfer/layui_exts/transfer/'
    }).use(['transfer'],function () {
        transfer = layui.transfer,
            $ = layui.$;

        $.ajax({
            type:'get',
            url:'/supplier/getAll',
            data:{},
            dataType:'json',
            success:function (res){

                tableList1(res.suppliers);
            }
        })



    })

    function tableList1(dat){
        //数据源
        var data1 = dat;
        //初始化可以无数据
        var data2 = [];
        //表格列
        var cols = [
            {checkbox : true,fixed : true},
            {field: 'name', title: '名称'},
            {field: 'outsideUser', title: '联系人'},
            {field: 'outsidePhone', title: '电话'}
        ]
        //表格配置文件
        var tabConfig = {'page':true}

        var tb1 = transfer.render({
            elem: "#root", //指定元素
            cols: cols, //表格列  支持layui数据表格所有配置
            data: [data1,data2], //[左表数据,右表数据[非必填]]
            tabConfig: tabConfig //表格配置项 支持layui数据表格所有配置

        })


        //transfer.get(参数1:初始化返回值,参数2:获取数据[all,left,right,l,r],参数:指定数据字段)
        //获取数据
        $('#queding').on('click',function(){
            var data = transfer.get(tb1,'right','name');
            var data1 = transfer.get(tb1,'right','id');

            console.log(data1);
            console.log(data);

            parent.$("#suppliers").val(data);
            parent.$("#supplierIds").val(data1);

            //关闭当前弹框
            var index =parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
            parent.layer.close(index);//再执行关闭


        });
        $("#quxiao").on('click',function(){
            var index =parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
            parent.layer.close(index);//再执行关闭
        })
    }

</script>
</body>
</html>